<template>
    <div id="home">
        <div class="topbar">
            <img src="./menu.svg" alt="" class="menu">
            <span>今天</span>
            <img src="./notify.svg" alt="" class="notify">
            <img src="./more.svg" alt="" class="more">
        </div>
        <div class="hot-story">
            <div class="box">
                <div class="item" v-for="item in hotStory">
                    <img :src="item.image" alt="">
                    <p>{{item.title}}</p>
                </div>
            </div>
        </div>
        <div class="all-story">
            <ul>
                <li v-for ="item in allStory"> 
                    <div class="title"><span>{{item.title}}</span></div>
                    <img :src="item.images[0]" alt="">
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
import axios from 'axios'
axios.defaults.baseURL = '/api'
export default {
    data() {
        return {
            hotStory:[],
            allStory:[]
        }
    },
    mounted(){
        axios.get('4/news/latest').then((rsp) =>{
            console.log(rsp);
            this.allStory = rsp.data.stories;
            this.hotStory = rsp.data.top_stories;
            console.log(this.hotStory)
        }).catch((error) =>{
           console.log(error)
        })
    }
}
</script>
<style scoped>
.topbar{
    width: 100%;
    height: 50px;
    background-color: #00a2ed;
    position: relative;
}
.topbar img{
    width: 30px;
    height: 30px;
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto 0;
}
.topbar .menu{
    left: 10px;
}
.topbar .notify{
    right: 50px;
}
.topbar .more{
    right: 10px;
}
.topbar span{
    position: absolute;
    font-size: 20px;
    left: 60px;
    top: 11px;
    color: #fff;
}
.hot-story{
    width: 100%;
    height: 200px;
    background-color: #ccc;
    overflow: hidden;
    position: relative;
}
.hot-story .box{
    width: 500%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    animation: loop 30s linear infinite;
}
.hot-story .box .item{
    width: 20%;
    height: 100%;
    float: left;
}
.item img{
    width: 100%;
    height: 100%;
}
.item p{
    width: 20%;
    height: 50px;
    background-color: rgba(0, 0, 0, 0.5);
    position: absolute;
    bottom: 0;
    padding-left: 10px;
    color: #fff;
    line-height: 50px;
    font-size: 16px;
    text-indent: 1em;
}
.all-story{
    width: 100%;
    margin-top: 10px;
}
.all-story ul{
    width: 95%;
    height: 80px;
    margin: 10px;
}
.all-story ul li{
    width: 95%;
    height: 80px;
    margin: 10px;
    box-shadow: 0 0 10px 0 #808080;
}
.all-story ul li .title{
    width: 70%;
    height: 100%;
    float: left;
}
.all-story ul li .title span{
    padding: 20px;
    display: block;
    font-size: 14px
}
.all-story ul li img{
    width: 23%;
    height: 70px;
    float: right;
    padding-top: 5px;
    margin-right: 10px;
}

@keyframes loop {
    0%,19%,100%{transform: translate(0,0)}
    20%,39%{transform: translate(-20%,0)}
    40%,59%{transform: translate(-40%,0)}
    60%,79%{transform: translate(-60%,0)}
    80%,99%{transform: translate(-80%,0)}
}
</style>

